package com.example.protestgps;

import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.util.Log;

public class SensorAccelerometer extends Activity implements SensorEventListener {
	
	Sensor accelerometer;
	SensorManager sm;
	float x;
	float y;
	float z;
	double a;
	

	public SensorAccelerometer(){
		
	}
	
	
	public SensorAccelerometer(SensorManager smparam){
	//sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
	this.sm = smparam;
	accelerometer = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
	sm.registerListener(this,accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
	}
	


	
	@Override
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onSensorChanged(SensorEvent event) {
		// TODO Auto-generated method stub
		if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER){
			 x = event.values[0];
			 y = event.values[1];
			 z = event.values[2];
		 //   System.out.println("x"+x);	
			 a = Math.sqrt(Math.pow(x,2)+Math.pow(y,2));
		//	 System.out.println("a: "+a);	
			geta();
		}
	}
	
	

	public double geta() {
		//System.out.println("x sensor"+this.x);
		return a;
	}

}
 